package webdev.adapters;

import java.util.ArrayList;

import webdev.dto.CommentDTO;
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import dev.danang.R;

public class ListPlaceViewCommentAdapter extends BaseAdapter {

	private static final String TAG = "ListPlaceViewCommentAdapter";
	
	private Context mContext;
	private Resources mResource;
	private ArrayList<CommentDTO> datas;
	
	// LayoutInflater
	private LayoutInflater mInflater;
	
	public ListPlaceViewCommentAdapter(Context _context) {
		this.mContext = _context;
		datas = new ArrayList<CommentDTO>();
		mResource = _context.getResources();
		mInflater = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	public void addComment(CommentDTO comment) {
		datas.add(comment);
	}
	
	@Override
	public int getCount() {
		return datas.size();
	}
	
	@Override
	public CommentDTO getItem(int position) {
		return datas.get(position);
	}
	
	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.item_list_comment,null);
			viewHolder = new ViewHolder();
			
			viewHolder.mImgAvatarUser = (ImageView) convertView.findViewById(R.id.img_avatar_user_of_item_list_comment);
			viewHolder.mTxtUserName = (TextView) convertView.findViewById(R.id.txt_comment_user_name_of_item_list_comment);
			viewHolder.mTxtContentComment = (TextView) convertView.findViewById(R.id.txt_comment_content_of_item_list_comment);
			
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		
		viewHolder.mTxtUserName.setText(getItem(position).getUserName());
		viewHolder.mTxtContentComment.setText(getItem(position).getContent());
		
		return convertView;
	}
	
	private class ViewHolder {
		ImageView mImgAvatarUser;
		TextView mTxtUserName;
		TextView mTxtContentComment;
//		TextView mTxtDate;
	}
}
